<!DOCTYPE html>
<html>
    <head>
        <title>Preview Display</title>
        <meta charset="UTF-8">
        <link rel="shortcut icon" href="custom/images/favicon.ico?v=2" />
        <style>
            html, body {
                padding: 0px;
                margin: 0px;
            }
        </style>


        <script src='../libs/jquery-3.4.1.min.js'></script>

        <script src='../libs/core/IZrowIfUVaXF.js'></script>
        <script src='../libs/core/VT3MIEkV8AKv.js'></script>
        <script src='../libs/core/ht.js'></script>
        <script src='../libs/core/buckle.js'></script>
        <script src='../libs/plugin/ht-edgetype.js'></script>
        <script src="../libs/plugin/ht-obj.js"></script>
        <script src='../libs/core/ht-ui.js'></script>
        <script src='../libs/plugin/ht-form.js'></script>
        <script src='../libs/plugin/ht-vector.js'></script>
        <script src="../libs/axios.min.js"></script>

        <script src="../libs/plugin/common.js"></script>
        <script src="../libs/echarts.js"></script>
        <script src="../configs/urlConfig.js"></script>

        <!-- <script src='../libs/core/ht.js'></script>
        <script src='../libs/core/ht-ui.js'></script>
        <script src='../configs/htconfig.js'></script>
        <script src='../libs/echarts.js'></script>
        
        <script src='../libs/ht-edgetype.js'></script>
        <script src='../libs/ht-obj.js'></script>
        <script src='../libs/ht-form.js'></script>
        <script src='../libs/ht-vector.js'></script>
        <script src='../libs/jquery-3.4.1.min.js'></script>
        <script src="../configs/urlConfig.js"></script> -->

        <script>
            function init() {
                dataModel = new ht.DataModel();
                graphView = new ht.graph.GraphView(dataModel);
                graphView.addToDOM();
                graphView.deserialize('displays/冀北/登录/登录.json', function(text) {
                    var json = ht.Default.parse(text);
                    dataModel.deserialize(json);
                    graphView.fitContent(true);
                    var a = dataModel.getDataByTag("radio");
                    var udm = dataModel.getDataByTag("username");
                    var pdm = dataModel.getDataByTag("password");
                    var spdm = dataModel.getDataByTag("savepwd");

                    if(getCookie('u')&& getCookie('p')){
                        udm.a('ht.value',getCookie('u'));
                        pdm.a('ht.value',getCookie('p'));
                        spdm.a('ht.checked',true);
                    }


                });
                $(document).keyup(function(e){
                    var udm = dataModel.getDataByTag("username");
                    var pdm = dataModel.getDataByTag("password");
                    var spdm = dataModel.getDataByTag("savepwd");
                    var key = e.which;
                    if(key==13){
                        login( udm.a('ht.value'),pdm.a('ht.value'),spdm.a('ht.checked'));
                    }
                });
            }
            function setCookie(name,value,day){
                var date = new Date();
                date.setDate(date.getDate() + day);
                document.cookie = name + '=' + value + ';expires='+ date;
            };
            function getCookie(name){
                var reg = RegExp(name+'=([^;]+)');
                var arr = document.cookie.match(reg);
                if(arr){
                return arr[1];
                }else{
                return '';
                }
            };
            function delCookie(name){
                setCookie(name,null,-1);
            }

            function login(username,password,spwd) {
                var httpRequest = new XMLHttpRequest();//第一步：创建需要的对象
                httpRequest.withCredentials = true;
                httpRequest.open('POST', window.location.origin + '/cas/jwt/login.do', true); //第二步：打开连接
                httpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");//设置请求头 注：post方式必须设置请求头（在建立连接后设置请求头）
                httpRequest.send('username='+username+'&password='+password);//发送请求 将情头体写在send中
                /**
                * 获取数据后的处理程序
                */
                httpRequest.onreadystatechange = function () {//请求后的回调接口，可将请求成功后要执行的程序写在其中
                    if (httpRequest.readyState == 4 && httpRequest.status == 200) {//验证请求是否发送成功
                        var json = httpRequest.responseText;//获取到服务端返回的数据
                        console.log(json);
                        if(JSON.parse(json).returnStatus == '200'){
                            debugger;
                            if(spwd){
                                //保存 Cookie
                                setCookie('u',username,30);
                                setCookie('p',password,30);
                            } else {
                                delCookie('u');
                                delCookie('p');
                            }
                            window.location.href = window.location.origin + '/portal/pageView?pageId=index';
                        } else {
                            if(JSON.parse(json).returnInfo === "已登录"){
                                window.location.href = window.location.origin + '/portal/pageView?pageId=index';
                            } else {
                                alert(JSON.parse(json).returnInfo);
                            }
                        } 
                        
                    }
                };
            }
            

        </script>
    </head>
    <body onload='setTimeout(init, 300)'>
    </body>
</html>
